<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Getting it to Work
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial004.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial006.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H1 CLASS="chapter"><A NAME="htoc35">Chapter&nbsp;4</A>&nbsp;&nbsp;Getting it to Work</H1><UL>
<LI><A HREF="tutorial005.html#toc13">Stubs</A>
<LI><A HREF="tutorial005.html#toc14">Argument checking</A>
<LI><A HREF="tutorial005.html#toc15">Early testing</A>
<LI><A HREF="tutorial005.html#toc16">Line Coverage</A>
<LI><A HREF="tutorial005.html#toc17">Heeding warnings</A>
<LI><A HREF="tutorial005.html#toc18">Keep it working</A>
</UL>

<A NAME="gettingittowork"></A>
Once the initial design is finished, and the top-level structure of the program has been defined, we should convert this specification into workable code as quickly as possible. Problems with the parameter passing, missing information or a wrong sequence of the data flow can be detected much more easily this way. We propose to use stubs and dummy code to get an (incomplete) implementation directly from the specification.<BR>
<BR>
<A NAME="toc13"></A>
<H2 CLASS="section"><A NAME="htoc36">4.1</A>&nbsp;&nbsp;Stubs</H2>
<A NAME="@default92"></A>Each query has been defined in form of a predicate, with input and output parameters. Regardless of the actual function of the query, it is easy to generate a predicate which syntactically behaves like the finished program. It reads the input parameters and creates output terms which satisfy the specification. Initially, it does not matter if the output parameters are not consistent with the input values, as long as their form is correct.<BR>
<BR>
If a top-level query has already been revised into smaller components, we can immediately write the body of the top-level predicate calling the individual components in the right order and with the correct parameters. Adding stub definitions of these components again leads to an executable program.<BR>
<BR>
Whenever we finish development of some of the components, we can immediately replace the stub code with the working implementation. Provided that the inputs are sufficiently simple, we get a simulated version of our application that we can convert piece by piece into the real application.<BR>
<BR>
<A NAME="toc14"></A>
<H2 CLASS="section"><A NAME="htoc37">4.2</A>&nbsp;&nbsp;Argument checking</H2>
<A NAME="@default93"></A>It is a good idea, at least for the top-level queries, to verify all parameters systematically. In the specification, we have defined various constraints that the input data must satisfy. Most of these constraints can be translated without too much work into checks that verify the constraints. A separate module for error checking can handle this work and leave the application core to rely on the correctness of the data.<BR>
<BR>
In RiskWise, the module <I>error_checking</I><A NAME="@default94"></A> performs these checks, using a simple language to define data constraints into executable rules.<BR>
<BR>
<A NAME="toc15"></A>
<H2 CLASS="section"><A NAME="htoc38">4.3</A>&nbsp;&nbsp;Early testing</H2>
Experience has shown that the testing<A NAME="@default95"></A> and tuning<A NAME="@default96"></A> of an application are by far the most time consuming activities in the development of a LSCO system. It is very important that we prepare test data sets as early as possible, together with some test routines which exercise our API queries with these tests.<BR>
<BR>
If we use different test sets <A NAME="@default97"></A>right from the start on our stub implementation, then we can detect problems early on during the development of individual components.<BR>
<BR>
<A NAME="toc16"></A>
<H2 CLASS="section"><A NAME="htoc39">4.4</A>&nbsp;&nbsp;Line Coverage</H2>
Another tool that is very useful at this stage of development is the line coverage <A NAME="@default98"></A>profiler <A NAME="@default99"></A>in the <I>coverage</I><A NAME="@default100"></A> library. Running this tool on the stub implementation we can check that each piece of code is exercised by our test sets.<BR>
<BR>
<A NAME="toc17"></A>
<H2 CLASS="section"><A NAME="htoc40">4.5</A>&nbsp;&nbsp;Heeding warnings</H2>
When we load our first implementation into the ECLiPSe system, it is quite possible that we find a number of error<A NAME="@default101"></A> and warning messages<A NAME="@default102"></A>. Errors will usually be caused by simple syntax problems, by forgetting to define some predicate or by not importing a module where it is required. These errors are typically easy to fix once we understand which part of the program is responsible.<BR>
<BR>
It is tempting to ignore warnings in order to get the code running as quickly as possible. That would be a big mistake. We should eliminate all warnings about singleton variables<A NAME="@default103"></A> and missing predicate <A NAME="@default104"></A>definitions before continuing. Not only will this lead to the detection of problems in the code at this point, we will also immediately see if new warnings are introduced when we change some part of the program. <BR>
<BR>
<A NAME="toc18"></A>
<H2 CLASS="section"><A NAME="htoc41">4.6</A>&nbsp;&nbsp;Keep it working</H2>
As a general rule, once we have created a working stub system, we should always keep the program working by making changes in small increments and testing after each change. This way we know which part of the program was modified last and which is therefore most likely to cause the problem. <BR>
<BR>
<HR>
<A HREF="tutorial004.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial006.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
